/*
 * File:     wiiuseconnector.h
 * Authors:  Dominic Stalder, Thomas Bruederli
 *
 * Thread class definition to connect to bluetooth Wii devices using the wiiuse library.
 *
 * This file is part of the Qt-based cross-platform Balance Blocks Game
 *
 * Copyright (C) 2009-2010, Dominic Stalder & Thomas Bruederli
 * Licensed under the GNU Lesser General Public License (LGPL) as published
 * by the Free Software Foundation at http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * $Id: wiiuseconnector.h 6 2010-03-03 09:58:46Z roundcube $
 */

#ifndef WIIUSECONNECTOR_H
#define WIIUSECONNECTOR_H

#include <QThread>
#include <QMutex>
#ifdef WIN32
	// use different header which fits the linked wiiuse.dll
	#include "lib/wiiuse/wiiuse.win.h"
#else
	#include "lib/wiiuse/wiiuse.h"
#endif

// number of wiimotes to be initialized
#define MAX_WIIMOTES 4

// forward declaration
class WiiDeviceDriver;


/**
 * Class declaration for the wiiuse thread
 */
class WiiuseConnector : public QThread
{
Q_OBJECT

private:
	static WiiuseConnector* instance;

	QMutex mutex;
	wiimote** wiimotes;
	WiiDeviceDriver* drivers[MAX_WIIMOTES];
	WiiDeviceDriver* wiimoterequest;

	int running, connected, state, clients;

	WiiuseConnector();
	~WiiuseConnector();

	void connect(void);
	void poll(void);
	void reset(void);
	void stop(void);

public:
	bool wait(void);
	bool requestWiimote(WiiDeviceDriver*);
	void disconnect(WiiDeviceDriver*);

	static WiiuseConnector* getInstance();

protected:
	void run();
};

#endif // WIIUSECONNECTOR_H
